package smb;

import static org.junit.Assert.assertTrue;

import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IDebugProperty;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that PwnU2 moves to all four corners per its specified strategy. Note:
 * portion of code came from professor johnson code.
 * 
 * @author Shoji Bravo
 * 
 */
public class TestPwnUDistance extends RobotTestBed {

 /** True if distance is 200 more. */
 boolean distFar = false;
 int disFar = 0;
 /** True if distance is 31 more but less than 199. */
 boolean distMid = false;
 int disMid = 0;
 /** True if distance is less than 30. */
 boolean distShort = false;
 int disShort = 0;

 /**
  * Specifies that Crazy and PwnU2 are to be matched up in this test case.
  * 
  * @return The comma-delimited list of robots in this match.
  */
 @Override
 public String getRobotNames() {
  return "sample.Crazy,smb.PwnU2";
 }

 /**
  * This test runs for 1 round.
  * 
  * @return The number of rounds.
  */
 @Override
 public int getNumRounds() {
  return 10;
 }

 /**
  * After each turn, check to see if we're at a corner. If so, set the
  * corresponding flag.
  * 
  * @param event
  *         Info about the current state of the battle.
  */
 @Override
 public void onTurnEnded(TurnEndedEvent event) {
  IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];

  /*
   * Determine the distance of the target when scanned. Knowing the distance,
   * able to determine power of fire.
   */
  for (IDebugProperty buggy : robot.getDebugProperties()) {
   // targetDistance
   if (buggy.getKey().compareToIgnoreCase("targetDistance") == 0) {
    if (Double.parseDouble(buggy.getValue()) > 400) {
     distFar = true;
     disFar++;
    }
    else if (Double.parseDouble(buggy.getValue()) < 399
      && Double.parseDouble(buggy.getValue()) > 200) {
     distMid = true;
     disMid++;
    }
    else if (Double.parseDouble(buggy.getValue()) < 199) {
     distShort = true;
     disShort++;
    }
   }

  }

 }

 /**
  * After the battle, check to see that we've visited the corners.
  * 
  * @param event
  *         Details about the completed battle.
  */
 @Override
 public void onBattleCompleted(BattleCompletedEvent event) {

  assertTrue("Check Distance Far", distFar);
  assertTrue("Check Distance Mid", distMid);
  assertTrue("Check Distance Short", distShort);

  System.out.println("Amount of times distance was far range = " + disFar);
  System.out.println("Amount of times distance was mid range = " + disMid);
  System.out.println("Amount of times distance was short range = " + disShort);

 }

}
